package com.zy.garbage.repository;

import com.zy.garbage.entity.Question;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface QuestionRepository extends JpaRepository<Question,Integer> {
    List<Question> findAllByExamId(Integer examId);
    List<Question> findAllByGarbageId(Integer garbageId);

    @Query(value = "select distinct garbage_id  from question group by garbage_id order by count(*) DESC limit 20",nativeQuery = true)
    List <Integer> findAllGroupByGarbageId();

    @Query(value = "select count(*) from question where garbage_id=:garbageId and answer_id=sort_id",nativeQuery = true)
    Integer findYesByGarbageId(Integer garbageId);

    @Query(value = "select count(*) from question where garbage_id=:garbageId and answer_id!=sort_id",nativeQuery = true)
    Integer findNoByGarbageId(Integer garbageId);

    @Query(value = "select count(*) from question where garbage_id=:garbageId and answer_id is null",nativeQuery = true)
    Integer findNoneByGarbageId(Integer garbageId);
}
